<%@page import="java.sql.Statement"%>
<%@page import="com.mysql.jdbc.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<%
String useridMessage = null;
String pw2Message = null;
String emailMessage = null;
String pw2= null;
String email = null;
String userid = null;
String pw1 = null;
if (request.getParameter("userid")!= null)
	userid = request.getParameter("usreid");
	pw1 = request.getParameter("pw1");
	pw2 = request.getParameter("pw2");
	email = request.getParameter("email");
	boolean valid = true;
	if (userid.length()<4 || userid.length()>20){
		valid = false;
		useridMessage ="使用者帳號長度不符";
		
	}
	if (!pw1.equals(pw2)){
		valid = false;
		pw2Message ="密碼長度不符";
	}
	if (email.indexOf("@")==-1){
		valid = false;
		emailMessage = "email格式不對";
	}
	if (valid){
		//1
		 DriverManager.deregisterDriver(new com.mysql.jdbc.Driver());
		//Class.forName("com.mysql.jdbc.Driver");
		java.sql.Connection conn =DriverManager.getConnection(
				"jdbc:mysql://j.snpy.org/j102", "jstu", "abc123");
		Statement stmt = conn.createStatement();
		String sql = "Inster into users (id,password,email) values ('"+userid+"' ,'"+pw1+"', '"+email+"')"; 
		System.out.println(sql);
		int rowCount = stmt.executeUpdate(sql);
		System.out.println(rowCount);
		} 
	
%>	

<body>
<form action="">
  帳號:<input id="userid" name="userid" type="text" value=" "/><%=useridMessage == null? "": useridMessage %><span id="userid_msg"></span>
       <img id="check_userid">(必填欄位,請輸入4~16位元字母)
<br/><br/>
  密碼:<input id="pw1" name="pw1" type="text" value=" "/><%=pw1 == null? "": pw1 %> <span id="pw1_msg"></span>
  (必填欄位,請輸入4~20位元字母)
<br/><br/>
  密碼:<input id="pw2" name="pw2" type="text" value=" "/><%=pw2 == null? "": pw2 %><span id="pw2_msg">(請再輸入一次密碼)</span>
<br/><br/>
  E-mail:<input name="email" type="text" value=" "/>(必填欄位)
<br/><br/>
email:<input id="email" name="email" type="text" value=" "/><%=email == null? "":email%> <span id="tel_msg"></span>
<br/><br/>
<input type="submit" value="註冊"/>
</form>
</body>
</html>